/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-09-19
 * Time: 16:58
 */
public class ThreadDemon18 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("线程正在运行");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });
        System.out.println("t1为NEW状态："+t1.getState());
        t1.start();//开始执行线程
        System.out.println("t1是RUNNABLE状态" + t1.getState());
        t1.join();//main等待t1线程执行完毕         //想要获取WAITING状态把这一行屏蔽掉
        Thread.sleep(500);//这里是确保让下一句不要那么快执行，正好让 Thread在sleep（1000）的期间获取状态
        System.out.println("t1是TERMINATED状态"+t1.getState());
    }
}
